window.onload = function () {
    document.getElementById('btn').onclick = function () {
        let usernameVal = username.value;
        let passwordVal = password.value;
        let data = 'username=' + usernameVal + '&password=' + passwordVal
        const xhr = new XMLHttpRequest();
        xhr.open('POST', '/backstage/login', true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr.setRequestHeader('user-token', usernameVal);
        xhr.responseType = 'json';
        xhr.send(data);
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                let result = xhr.response;
                if (result.code == 200) {
                    sessionStorage.setItem("token",result.token)
                    location.href = result.url;
                } else {
                    document.getElementById('tips').textContent = result.msg;
                }
            }
        }
    }
}